package com.test;

import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.onlyxiahui.framework.net.session.AbstractSession;
import com.onlyxiahui.framework.net.session.SessionBox;
import com.onlyxiahui.framework.net.session.SocketSession;

/**
 * 
 * Date 2018-12-30 14:16:11<br>
 * Description
 * 
 * @author XiaHui<br>
 * @since 1.0.0
 */
public class ConcurrentHashMapTest1 {

	public static void main(String[] arg) {
		int count = 20;
		final SessionBox sb = new SessionBox();
		SocketSession session = new AbstractSession() {

			String id = UUID.randomUUID().toString().replace("-", "");

			@Override
			public String getId() {
				return id;
			}

			@Override
			public void write(Object object) {

			}

			@Override
			public void close() {

			}

			@Override
			public String getRemoteAddress() {
				return "";
			}

		};

		session.setKey("user");
		ExecutorService pool = new ThreadPoolExecutor(count, count, 0L, TimeUnit.MILLISECONDS,
				new LinkedBlockingQueue<Runnable>());
		for (int i = 0; i < count; i++) {
			pool.execute(new Runnable() {

				@Override
				public void run() {
					for (int i = 0; i < 100; i++) {
						sb.put(session);
//						new Thread() {
//							public void run() {
//								for (int i = 0; i < 100; i++) {
//									sb.put(session);
//								}
//							}
//						}.start();
					}
				}
			});
		}
	}
}
